<?php
namespace English\Controller;

use Think\Page;
use app\English\Controller\Base;
class HangqingController extends BaseController
{
    public function index()
    {

        $RewardConfig = M('reward_config')->where(['id'=>1])->field('')->find();
    
        $this->assign('RewardConfig',$RewardConfig);
//       $btc= $this->testApi('BTC');
//       $eth= $this->testApi('ETH');
//       $ltc= $this->testApi('LTC');

        $this->display();
    }

    public function search_rate(){
        $exuu=M('reward_config')->where('id=1')->field('p2,p5,dacm_float')->find();
//        dump($exuu);die;
        ajax_return('1',$exuu);
    }

    public function api(){
        //       $wfx= $this->testApi('WFX');

       // $data['btc']= $this->testApi('BTC');
       // $data['eth']= $this->testApi('ETH');
       // $data['ltc']= $this->testApi('LTC');
      
     // $data['eos']=$this->testApi('EOS');
      // $data['bnb']=$this->testApi('BNB');
      // $data['xlm']=$this->testApi('XLM');
      // $data['ada']=$this->testApi('ADA');
    //  $data['neo']=$this->testApi('NEO');
      
     //   $data['OMG']= $this->testApi('OMG');
      //  $data['USDT']= $this->testApi('USDT');
     //   $data['PPT']= $this->testApi('PPT');
      //  $data['TRIP']= $this->testApi('TRIP');
     //   $data['CT']= $this->testApi('CT');
//        dump($data);die;
      $data=$this->testApi();
      $config=M('reward_config')->find();
      $data['config']=$config;
         echo json_encode($data);

    }
    public function testApi($type='BTC')
    {
        //獲取BTC價格寫入數據庫
   //    $url = "http://www.coinyee.pro/app/v1/ThirdpartyController/markets?coin=".$type."&unit=cny&tdsourcetag=s_pcqq_aiomsg";
      // $url = " https://api.shenjian.io/?appid=ef09ed7301060858d32af37380bc8095&coin=bitcoin&currency=BTC";
       // $url = "http://api.coindog.com/api/v1/tick/Binance:".$type."USDT?unit=cny";
       $url = "https://api.jinse.com/v3/coin/detail?slugs=tether&_source=m";
        $btcData = $this->https_request($url);
        $btcData = json_decode($btcData, true);
   		return $btcData;
        //return $btcData['data']['obj'];die;
//        dump($btcData);die;
//       echo $btcData['data']['obj'];die;
//        dump($btcData);die;
//        $btcPrice = $btcData['close'];
//        $info['canshu60'] = $btcPrice;
//        M('config')->where(['id'=>1])->save($info);
//        $uid = $this->create_guid();
//        echo $uid;

    }
    public function test($type='BTC')
    {
        //獲取BTC價格寫入數據庫
      //  $url = "http://www.coinyee.pro/app/v1/ThirdpartyController/markets?coin=".$type."&unit=cny&tdsourcetag=s_pcqq_aiomsg";
        $url = "http://api.coindog.com/api/v1/tick/Binance:".$type."USDT?unit=cny";
   		
        $btcData = $this->https_request($url);
        $btcData = json_decode($btcData, true);
       dump($btcData);die;


    }
    function https_request($url,$data = null){
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)){
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }


}